package com.baosight.sczx.zm.ck.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.ck.domain.ZMCKPSSB;

/**
 * 
 * <p>Title: ServiceZMCK34.java</p>
 * <p>Description: 排水设备检查记录</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年9月18日 上午10:23:47  郭淑芳  Create
 *</pre>
 */
public class ServiceZMCK34 extends ServiceEPBase {
	/**
	 * 初始进入方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCK34</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-25 上午14:37:20 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) 
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCK34</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-6-25 上午14:47:20 王开兵
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		// 供雨季三防汇总页面使用
		String flag = inInfo.getString("flag");
		if (null != flag && !("").equals(flag)) {
			StaticTools.setQueryParameters(inInfo, "fdStatus", "上报", true);// 添加查询条件
		} else {
			StaticTools.setQueryParameters(inInfo, "fdDepartmentId", UserSession.getInSessionProperty("miningCode"), true);
		}
		String fdDepartmentId = inInfo.getString("departmentId");
		if (null != fdDepartmentId && !("").equals(fdDepartmentId)) {
			StaticTools.setQueryParameters(inInfo, "fdDepartmentId", fdDepartmentId, true);
		}
		
		String nf = inInfo.getString("nf");
		if (null != nf && !("").equals(nf)) {
			String fdBeginDate = nf + "-01-01";
			String fdEndDate = nf + "-12-31";
			StaticTools.setQueryParameters(inInfo, "fdBeginDate", fdBeginDate, true);// 添加查询条件
			StaticTools.setQueryParameters(inInfo, "fdEndDate", fdEndDate, true);// 添加查询条件
		}
		EiInfo outInfo = super.query(inInfo, "ZMCKPSSB.query", new ZMCKPSSB());
		
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.ck.pssbXh", false));//水泵型号
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.ck.pssbScmc", false));//水仓名称
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.ck.pssbBfmc", false));//泵房名称
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.ch.status", new String[] { "草拟", "上报", "已发布" }, new String[] { "草拟", "上报", "已发布" }, false));// 状态

		outInfo.set("fdDepartmentId", UserSession.getInSessionProperty("miningCode"));//单位的默认值		
		outInfo.set("fdDepartment", UserSession.getInSessionProperty("miningName"));//单位的默认值
		
		return outInfo;
	}


	/**
	 * 
	 * <p>Function: insert</p>
	 * <p>Description: 新增方法</p>
	 * <p>return value: ServiceZMCK34</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:24:43 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCKPSSB _dom = new ZMCKPSSB();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			_dom.setFdDepartmentId(UserSession.getInSessionProperty("miningCode").toString());
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CK_PSSB"));
			_dom.setFdDocid(StaticTools.getDocId());
			this.dao.insert("ZMCKPSSB.insert", _dom);
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}

	/**
	 * 
	 * <p>Function: update</p>
	 * <p>Description: 修改方法</p>
	 * <p>return value: ServiceZMCK34</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:25:39 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCKPSSB _dom = new ZMCKPSSB();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			_dom.setFdCurrentDate(StaticTools.getDate());
			this.dao.update("ZMCKPSSB.update", _dom);
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}
	
	/**
	 * 
	 * <p>Function: delete</p>
	 * <p>Description: 删除方法</p>
	 * <p>return value: ServiceZMCK34</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:26:23 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp = super.delete(inInfo, "ZMCKPSSB.delete");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;	
	}
	
	/**
	 * 
	 * <p>Function: report</p>
	 * <p>Description: 上报方法</p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:27:02 郭淑芳
	 * </p>
	 *
	 */
	public EiInfo report(EiInfo inInfo) {
		EiInfo _temp = super.update(inInfo, "ZMCKPSSB.report");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;		
	}
}
